def wav_to_c_array(wav_file, output_file):
    # 以二进制模式读取WAV文件
    with open(wav_file, 'rb') as wav:
        # 读取所有二进制数据
        binary_data = wav.read()
        
        # 打开输出文件
        with open(output_file, 'w') as f:
            # 写入C数组的声明
            f.write(f"const uint8_t wav_data[{len(binary_data)}] = {{\n")
            
            # 每行显示16个字节
            for i in range(0, len(binary_data), 16):
                chunk = binary_data[i:i+16]
                hex_values = ', '.join(f'0x{byte:02X}' for byte in chunk)
                f.write(f"    {hex_values},\n")
            
            # 写入C数组的结束
            f.write("};\n")
        
        print(f"WAV文件已成功转换为C数组并保存到 {output_file}")

# 使用示例
wav_to_c_array('ding.wav', 'output1.c')